package com.heeexy.example.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.dao.GoodsDao;
import com.heeexy.example.service.GoodsService;
import com.heeexy.example.util.CommonUtil;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
   
    //添加商品
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject add(JSONObject jsonObject) {
        goodsDao.add(jsonObject);
    	return CommonUtil.successJson();
    }

    @Override
    //商品列表
    public JSONObject list(JSONObject jsonObject) {
        CommonUtil.fillPageParam(jsonObject);
        int count = goodsDao.countGoods(jsonObject);
        List<JSONObject> list =  goodsDao.list(jsonObject);
        return CommonUtil.successPage(jsonObject, list, count);

    }
    //修改商品
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject update(JSONObject jsonObject) {
        goodsDao.update(jsonObject);
    	return CommonUtil.successJson();
    }
    //删除商品
    @SuppressWarnings("unchecked")
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject delete(JSONObject jsonObject) {
        goodsDao.delete(jsonObject);
    	return CommonUtil.successJson();
    }
   
}
